home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / CPP / WFC010.ZIP / SRC / CSYSTE~1.CPP < prev    next >
C/C++ Source or Header  |  1995-12-05  |  6KB  |  311 lines

  1. #include <wfc.h>
  2. #pragma hdrstop
  3.  
  4. /*
  5. ** Author: Samuel R. Blackburn
  6. ** CI$: 76300,326
  7. ** Internet: sammy@sed.csc.com
  8. **
  9. ** You can use it any way you like as long as you don't try to sell it.
  10. **
  11. ** Any attempt to sell WFC in source code form must have the permission
  12. ** of the original author. You can produce commercial executables with
  13. ** WFC but you can't sell WFC.
  14. **
  15. ** Copyright, 1995, Samuel R. Blackburn
  16. **
  17. ** $Workfile: $
  18. ** $Revision: $
  19. ** $Modtime: $
  20. */
  21.  
  22. #if defined( _DEBUG )
  23. #undef THIS_FILE
  24. static char BASED_CODE THIS_FILE[] = __FILE__;
  25. #endif
  26.  
  27. #if defined( _DEBUG )
  28. #define new DEBUG_NEW
  29. #endif
  30.  
  31. CSystemTime::CSystemTime()
  32. {
  33.    Empty();
  34. }
  35.  
  36. CSystemTime::CSystemTime( const CSystemTime& source )
  37. {
  38.    Copy( source );
  39. }
  40.  
  41. CSystemTime::CSystemTime( const SYSTEMTIME * source )
  42. {
  43.    Copy( source );
  44. }
  45.  
  46. CSystemTime::~CSystemTime()
  47. {
  48.    Empty();
  49. }
  50.  
  51. LONG CSystemTime::Compare( const CSystemTime& source )
  52. {
  53.    if ( wYear < source.wYear )
  54.    {
  55.       return( (-1) );
  56.    }
  57.  
  58.    if ( wYear > source.wYear ) 
  59.    {
  60.       return( 1 );
  61.    }
  62.  
  63.    if ( wMonth < source.wMonth )
  64.    {
  65.       return( (-1) );
  66.    }
  67.  
  68.    if ( wMonth > source.wMonth ) 
  69.    {
  70.       return( 1 );
  71.    }
  72.  
  73.    if ( wDay < source.wDay )
  74.    {
  75.       return( (-1) );
  76.    }
  77.  
  78.    if ( wDay > source.wDay ) 
  79.    {
  80.       return( 1 );
  81.    }
  82.  
  83.    if ( wHour < source.wHour )
  84.    {
  85.       return( (-1) );
  86.    }
  87.  
  88.    if ( wHour > source.wHour ) 
  89.    {
  90.       return( 1 );
  91.    }
  92.  
  93.    if ( wMinute < source.wMinute )
  94.    {
  95.       return( (-1) );
  96.    }
  97.  
  98.    if ( wMinute > source.wMinute ) 
  99.    {
  100.       return( 1 );
  101.    }
  102.  
  103.    if ( wSecond < source.wSecond )
  104.    {
  105.       return( (-1) );
  106.    }
  107.  
  108.    if ( wSecond > source.wSecond ) 
  109.    {
  110.       return( 1 );
  111.    }
  112.  
  113.    if ( wMilliseconds < source.wMilliseconds )
  114.    {
  115.       return( (-1) );
  116.    }
  117.  
  118.    if ( wMilliseconds > source.wMilliseconds ) 
  119.    {
  120.       return( 1 );
  121.    }
  122.  
  123.    return( 0 );
  124. }
  125.  
  126. void CSystemTime::Copy( const CSystemTime& source )
  127. {
  128.    Copy( (const SYSTEMTIME *) &source );
  129. }
  130.  
  131. void CSystemTime::Copy( const SYSTEMTIME * source )
  132. {
  133.    ASSERT( source != NULL );
  134.  
  135.    if ( source == (const SYSTEMTIME *) NULL )
  136.    {
  137.       Empty();
  138.       return;
  139.    }
  140.  
  141.    wYear         = source->wYear;
  142.    wMonth        = source->wMonth;
  143.    wDay          = source->wDay;
  144.    wDayOfWeek    = source->wDayOfWeek;
  145.    wHour         = source->wHour;
  146.    wMinute       = source->wMinute;
  147.    wSecond       = source->wSecond;
  148.    wMilliseconds = source->wMilliseconds;
  149. }
  150.  
  151. void CSystemTime::Copy( const CFileTime& source )
  152. {
  153.    Copy( (const FILETIME *) &source );
  154. }
  155.  
  156. void CSystemTime::Copy( const FILETIME * source )
  157. {
  158.    ASSERT( source != NULL );
  159.  
  160.    if ( source == (const FILETIME *) NULL )
  161.    {
  162.       Empty();
  163.       return;
  164.    }
  165.  
  166.    SYSTEMTIME system_time;
  167.  
  168.    if ( ::FileTimeToSystemTime( source, &system_time ) == TRUE )
  169.    {
  170.       Copy( &system_time );
  171.    }
  172.    else
  173.    {
  174.       Empty();
  175.    }
  176. }
  177.  
  178. void CSystemTime::Empty( void )
  179. {
  180.    wYear         = 0;
  181.    wMonth        = 0;
  182.    wDay          = 0;
  183.    wDayOfWeek    = 0;
  184.    wHour         = 0;
  185.    wMinute       = 0;
  186.    wSecond       = 0;
  187.    wMilliseconds = 0;
  188. }
  189.  
  190. CSystemTime CSystemTime::GetTheCurrentTime( void )
  191. {
  192.    SYSTEMTIME system_time;
  193.  
  194.    ::GetSystemTime( &system_time );
  195.  
  196.    return( CSystemTime( &system_time ) );
  197. }
  198.  
  199. /*
  200. ** Operators
  201. */
  202.  
  203. CSystemTime& CSystemTime::operator = ( const CSystemTime& source )
  204. {
  205.    Copy( source );
  206.    return( *this );
  207. }
  208.  
  209. CSystemTime& CSystemTime::operator = ( const CFileTime& source )
  210. {
  211.    Copy( source );
  212.    return( *this );
  213. }
  214.  
  215. BOOL CSystemTime::operator == ( const CSystemTime& source )
  216. {
  217.    if ( Compare( source ) == 0 )
  218.    {
  219.       return( TRUE );
  220.    }
  221.    else
  222.    {
  223.       return( FALSE );
  224.    }
  225. }
  226.  
  227. BOOL CSystemTime::operator > ( const CSystemTime& source )
  228. {
  229.    if ( Compare( source ) > 0 )
  230.    {
  231.       return( TRUE );
  232.    }
  233.    else
  234.    {
  235.       return( FALSE );
  236.    }
  237. }
  238.  
  239. BOOL CSystemTime::operator < ( const CSystemTime& source )
  240. {
  241.    if ( Compare( source ) < 0 )
  242.    {
  243.       return( TRUE );
  244.    }
  245.    else
  246.    {
  247.       return( FALSE );
  248.    }
  249. }
  250.  
  251. #if defined( _DEBUG )
  252.  
  253. void CSystemTime::Dump( CDumpContext& dump_context ) const
  254. {
  255.    LPCTSTR months[ 12 ] = { "(January)",
  256.                             "(February)",
  257.                             "(March)",
  258.                             "(April)",
  259.                             "(May)",
  260.                             "(June)",
  261.                             "(July)",
  262.                             "(August)",
  263.                             "(September)",
  264.                             "(October)",
  265.                             "(November)",
  266.                             "(December)"
  267.                           };
  268.  
  269.    LPCTSTR days[ 7 ] = { "(Sunday)",
  270.                          "(Monday)",
  271.                          "(Tuesday)",
  272.                          "(Wednesday)",
  273.                          "(Thursday)",
  274.                          "(Friday)",
  275.                          "(Saturday)"
  276.                        };
  277.  
  278.    dump_context << "a CSystemTime at " << (VOID *) this << "\n{\n";
  279.    dump_context << "   wYear is " << wYear << "\n";
  280.    dump_context << "   wMonth is " << wMonth;
  281.  
  282.    if ( wMonth > 0 && wMonth < 13 )
  283.    {
  284.       dump_context << " " << months[ wMonth - 1 ] << "\n";
  285.    }
  286.    else
  287.    {
  288.       dump_context << " (Invalid)\n";
  289.    }
  290.  
  291.    dump_context << "   wDayOfWeek is " << wDayOfWeek;
  292.  
  293.    if ( wDayOfWeek < 7 )
  294.    {
  295.       dump_context << " " << days[ wDayOfWeek ] << "\n";
  296.    }
  297.    else
  298.    {
  299.       dump_context << " (Invalid)\n";
  300.    }
  301.  
  302.    dump_context << "   wDay is " << wDay << "\n";
  303.    dump_context << "   wHour is " << wHour << "\n";
  304.    dump_context << "   wMinute is " << wMinute << "\n";
  305.    dump_context << "   wSecond is " << wSecond << "\n";
  306.    dump_context << "   wMilliseconds is " << wMilliseconds << "\n";
  307.    dump_context << "}\n";
  308. }
  309.  
  310. #endif
  311.